package com.shuorikeji.huohuo.view;

import android.content.Context;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatImageView;

public class MhImageView extends AppCompatImageView {
    public MhImageView(Context context) {
        super(context);
        init();
    }

    public MhImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MhImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setScaleType(ScaleType.CENTER_CROP); // 或者使用 ScaleType.CENTER_INSIDE 根据需求选择
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        setMeasuredDimension(width, height); // 直接使用父容器的宽高，不进行缩放计算
    }
}
